using System;
using System.Collections.Generic;
using System.Text;
using Activa.CoolStorage;
using CodeStory.Core.ObjectEntity;

namespace CodeStory.Core.ObjectBusiness
{
	public sealed class RoleResourceBusiness
	{
		private RoleResourceBusiness() {

		}

		public static long GetRolePermission(Guid roleID,Guid resourceID) {
			long permission = 0;
			try {
				RoleResourceObject obj = RoleResourceObject.Read(roleID, resourceID);
				permission = obj.Permission;
			} catch {
			}

			return permission;
		}

		public static void InsertOrUpdateRoleResource(Guid roleID, Guid resourceID, long permission) {
			RoleResourceObject obj;
			try {
				obj = RoleResourceObject.Read(roleID, resourceID);
			} catch (CSObjectNotFoundException){
				obj = RoleResourceObject.New();
				obj.RoleID = roleID;
				obj.ResourceID = resourceID;
			}
			obj.Permission = permission;
			obj.Save();
		}
	}
}
